<%@ page import="com.tencent.albert.weixin.driver.bean.*" %>
<%@ page import="com.tencent.albert.weixin.driver.utils.WeixinUtil" %>
<%@ page import="com.tencent.albert.weixin.driver.Constants" %>
<%--
    Document   : createMenu
    Created on : 2014-12-25, 17:58:45
    Author     : albertzhu
--%>


<%@page contentType="text/html" pageEncoding="UTF-8"%>

<%!
    private static Menu getMenu() {



        /**菜单1**/
//        ViewButton btn11 = new ViewButton();
//        btn11.setName("品牌公寓");
//        btn11.setType("view");
//        btn11.setUrl("http://dwz.cn/1HYBa2");
//
//        ClickButton btn12 = new ClickButton();
//        btn12.setName("个人房源");
//        btn12.setType("click");
//        btn12.setKey("BTN_CLICK_FOR_2");

//        ComplexButton mainBtn1 = new ComplexButton();
//        mainBtn1.setName("我要找房");
//        mainBtn1.setSub_button(new Button[]{btn11,btn12});

//        ViewButton btn11 = new ViewButton();
//        btn11.setName("狂欢11.11");
//        btn11.setType("view");
//        btn11.setUrl("http://dwz.cn/25Q9Hu");
        ViewButton btn11 = new ViewButton();
        btn11.setName("品牌公寓");
        btn11.setType("view");
        btn11.setUrl("http://dwz.cn/25UT2T");

        ViewButton btn12 = new ViewButton();
        btn12.setName("个人房源");
        btn12.setType("view");
        btn12.setUrl("http://dwz.cn/2c9KS9");

        ViewButton btn13 = new ViewButton();
        btn13.setName("在线咨询");
        btn13.setType("view");
        btn13.setUrl("http://dwz.cn/1HZPqJ");

        ComplexButton mainBtn1 = new ComplexButton();
        mainBtn1.setName("我要找房");
        mainBtn1.setSub_button(new Button[]{btn12, btn11, btn13});
        /**菜单2**/

        ViewButton btn21 = new ViewButton();
        btn21.setName("双12特惠");
        btn21.setType("view");
        btn21.setUrl("http://dwz.cn/2jvXfZ");
//        ClickButton btn21 = new ClickButton();
//        btn21.setName("转租");
//        btn21.setType("click");
//        btn21.setKey("BTN_CLICK_FOR_3");
//
//        ClickButton btn22 = new ClickButton();
//        btn22.setName("招室友");
//        btn22.setType("click");
//        btn22.setKey("BTN_CLICK_FOR_4");
//
//        ComplexButton mainBtn2 = new ComplexButton();
//        mainBtn2.setName("我要出租");
//        mainBtn2.setSub_button(new Button[]{btn21,btn22});

//        ClickButton btn21 = new ClickButton();
//        btn21.setName("我要出租");
//        btn21.setType("click");
//        btn21.setKey("BTN_CLICK_FOR_21");

//        ViewButton btn21 = new ViewButton();
//        btn21.setName("急租！！！");
//        btn21.setType("view");
//        btn21.setUrl("http://dwz.cn/2eql9v");

//        /**菜单3**/
//        ViewButton btn31 = new ViewButton();
//        btn31.setName("0押金");
//        btn31.setType("view");
//        btn31.setUrl("http://dwz.cn/1HYCcW");

//        ViewButton btn32 = new ViewButton();
//        btn32.setName("领奖金");
//        btn32.setType("view");
//        btn32.setUrl("http://dwz.cn/1HYD9f");

//        ViewButton btn33 = new ViewButton();
//        btn33.setName("在线咨询");
//        btn33.setType("view");
//        btn33.setUrl("http://dwz.cn/1HZPqJ");

        ClickButton btn33 = new ClickButton();
        btn33.setName("免佣小秘书");
        btn33.setType("click");
        btn33.setKey("BTN_CLICK_FOR_mishu");

//        ComplexButton mainBtn3 = new ComplexButton();
//        mainBtn3.setName("客服");
//        mainBtn3.setSub_button(new Button[]{btn32,btn33});

        /**
         * 这是公众号xiaoqrobot目前的菜单结构，每个一级菜单都有二级菜单项<br>
         *
         * 在某个一级菜单下没有二级菜单的情况，menu该如何定义呢？<br>
         * 比如，第三个一级菜单项不是“更多体验”，而直接是“幽默笑话”，那么menu应该这样定义：<br>
         * menu.setButton(new Button[] { mainBtn1, mainBtn2, btn33 });
         */
        Menu menu = new Menu();
//        menu.setButton(new Button[]{btn11, btn21, mainBtn3});
        menu.setButton(new Button[]{ btn21,mainBtn1, btn33});

        return menu;
    }
%>

<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>JSP Page</title>
</head>
<body>
<h1>Hello World!</h1>

<%
    // 调用接口获取access_token
    AccessToken at = WeixinUtil.getAccessToken(Constants.appId, Constants.appSecret);

    if (null != at) {
        // 调用接口创建菜单
        int result = WeixinUtil.createMenu(getMenu(), at.getAccess_Token());
        //int result = 0;
        // 判断菜单创建结果
        if (0 == result) {
            out.println("菜单创建成功！");
        } else {
            out.println("菜单创建失败，错误码：" + result);
        }
    }

%>

</body>
</html>
